﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using XboxUserInterface.Settings;
using XboxUserInterface.Forms;
using XboxUserInterface.Variables;
using System.Threading;

namespace XboxUserInterface
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.  Loads all schemes from "schemes.xml" and adds them to Globals
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Operations.loadAllSchemes(Application.StartupPath + "\\schemes.xml");
            Application.ApplicationExit += new EventHandler(Application_ApplicationExit);

            Thread t = new Thread(new ThreadStart(splash));
            t.Start();
            Thread.Sleep(3000);
            t.Abort();
            Thread.Sleep(1000);
            Application.Run(new Service());
            
        }

        /// <summary>
        /// Saves all schemes to XML on exiting the program.
        /// </summary>
        /// <param name="sender">Program sending the call</param>
        /// <param name="e">Information for the call</param>
        static void Application_ApplicationExit(object sender, EventArgs e)
        {
            Operations.SaveGlobalSchemes();
        }

        /// <summary>
        /// Creates a new instance of the splash screen to use on startup
        /// </summary>
        static void splash()
        {
            Splash s = new Splash();
            s.ShowDialog();
        }
    }
}
